﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DD35.WebMVP.Presenters;
using AMS.DD35.WebMVP.Models;
using AMS.Core.Services;
using AMS.DD35.WcfConnector;

namespace AMS.DD35.WebMVP.Views
{
    public partial class RegisterView : System.Web.UI.Page, IRegisterView
    {
        RegisterPresenter _presenter;
        IRegisterModel _model;

        public string UserName
        {
            get { return txtUserName.Text; }
            set { txtUserName.Text = value; }
        }

        public string Password
        {
            get { return txtPassword.Text; }
            set { txtPassword.Text = value; }
        }

        public string ConfirmPassword
        {
            get { return txtConfirmPassword.Text; }
            set { txtConfirmPassword.Text = value; }
        }

        public string FirstName
        {
            get { return txtFirstName.Text; }
            set { txtFirstName.Text = value; }
        }

        public string LastName
        {
            get { return txtLastName.Text; }
            set { txtLastName.Text = value; }
        }

        public string EmailAddress
        {
            get { return txtEmail.Text; }
            set { txtEmail.Text = value; }
        }

        public string ConfirmEmail
        {
            get { return txtConfirmEmail.Text; }
            set { txtConfirmEmail.Text = value; }
        }

        public string Message
        {
            get { return lblMessage.Text; }
            set { lblMessage.Text = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            IRegisterService service = new RegisterProxy();
            _model = new RegisterModel(service);
            _presenter = new RegisterPresenter(this, _model);

            _model.RegistrationFailed += new EventHandler(HandleRegistrationFailed);
            _model.RegistrationSucceeded += new EventHandler(HandleRegistrationSucceeded);
        }

        protected void HandleSubmitButton_Click(object sender, EventArgs args)
        {
            _presenter.Register();
        }

        private void HandleRegistrationFailed(object sender, EventArgs args)
        {
            _presenter.RegisterFailed();
        }

        private void HandleRegistrationSucceeded(object sender, EventArgs args)
        {
            _presenter.RegisterSucceeded();
        }
    }
}
